<template>
  <div class="contents">
    <city-header></city-header>
    <city-search :cities='cities'></city-search>
    <city-list :cities= 'cities' :hotcities= 'hotcities' :location= 'location' :letter= 'letter'></city-list>
    <sidebar :cities= 'cities' @change= 'handleLetterChange'></sidebar>
  </div>
</template>

<script>
import axios from "axios"
import CityHeader from "./components/header.vue";
import CitySearch from "./components/search.vue";
import CityList from "./components/list.vue";
import Sidebar from "./components/sidebar.vue";
export default {
  name: "city",
  components: {
    CityHeader,
    CitySearch,
    CityList,
    Sidebar
  },
  data() {
    return {
      cities: {},
      hotcities: [],
      location: '',
      letter: ''
    }
    

  },
  methods: {
    getCityInfo () {
      axios.get('/api/city.json')
        .then(this.getCityInfoSucc)
    },
    getCityInfoSucc (res) {
      this.cities = res.data.data.cities
      this.hotcities = res.data.data.hotCities
      this.location = res.data.data.location
      // console.log(this.cities);
      // console.log(this.hotcities);
      // console.log(this.location);
      // console.log(res);
    },
    handleLetterChange (letter) {
      this.letter = letter
      // console.log(letter);
    }
  },
  mounted () {
    console.log(1)
    this.getCityInfo ()

  }
};
</script>
<style lang="stylus" scoped>
</style>